﻿using GameLogic.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameLogic
{
    class Map
    {
        private Dictionary<FieldPoint, GameObject> objectsMap;
        private List<GameObject> objects;
        private List<GameObject> aliveObjects;
        public int Width { get; set; }
        public int Height { get; set; }

        internal List<GameObject> Objects
        {
            get
            {
                return objects;
            }
            set
            {
                objects = value;
            }
        }

        internal List<GameObject> AliveObjects
        {
            get
            {
                return aliveObjects;
            }
            set
            {
                aliveObjects = value;
            }
        }

        public Map(int width, int height)
        {
            objectsMap = new Dictionary<FieldPoint, GameObject>();
            objects = new List<GameObject>();
            aliveObjects = new List<GameObject>();
            Width = width;
            Height = height;
        }

        // пока не используется
     /*   public GameObject this[int x, int y]
        {
            get
            {
                FieldPoint point = new FieldPoint(x, y);

                return objectsMap[point];
            }
            set
            {
                FieldPoint point = new FieldPoint(x, y);
                objectsMap[point] = value;
                objects.Add(value);
            }
        }*/

        internal static Map Generate(int width, int height, Random r)
        {

            var result = new Map(width, height);
            int cellH = width / Constants.CELL_SIZE;
            int cellV = height / Constants.CELL_SIZE;
            for (int i = 2; i < cellH - 2; i++)
            {
                for (int j = 0; j < cellV; j++)//первый и последний столбец - для танков
                {
                    if (r.NextDouble() <= Constants.BRICK_CREATION_PROBABILITY)
                    {
                        var brick = new Brick(i * Constants.CELL_SIZE, j * Constants.CELL_SIZE);
                        result.Objects.Add(brick);
                        result.AliveObjects.Add(brick);
                        //var position = new FieldPoint(j * Constants.CELL_SIZE, i * Constants.CELL_SIZE);
                        //brick.Position = position; 
                        //result[i, j] = brick;
                    }
                }
            }

            return result;
        }
    }
}
